package itertools

import "iter"

func Range(start, end int) iter.Seq[int] {
	return func(yield func(int) bool) {
		for current := start; current < end; current++ {
			if !yield(current) {
				return
			}
		}
	}
}

func Map[T any, U any](input []T, fn func(T) U) iter.Seq[U] {
	return func(yield func(U) bool) {
		for _, v := range input {
			if !yield(fn(v)) {
				return
			}
		}
	}
}

func Filter[T any](input []T, fn func(T) bool) iter.Seq[T] {
	return func(yield func(T) bool) {
		for _, v := range input {
			if !fn(v) {
				continue
			}
			if !yield(v) {
				return
			}
		}
	}
}
